package com.Hermes.User;

import javax.crypto.IllegalBlockSizeException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;

public class QueryTokenGen {
    private final PRF_PRP_Hash pph;
    private final ArrayList<tokenNode>data;
    private final ArrayList<Long> querylist;
    private ConcurrentHashMap<Long, Long> ii2i;

    public QueryTokenGen(PRF_PRP_Hash pph, ArrayList<Long> querylist, ConcurrentHashMap<Long,Long>ii2i) throws IllegalBlockSizeException {
        this.ii2i = ii2i;
        long tokenst=System.currentTimeMillis();
        this.pph = pph;
        this.querylist = querylist;
        data=new ArrayList<>();
        for (long t : querylist) {
            byte[] Imsg = new BigDecimal(ii2i.get(t)).toBigInteger().toByteArray(), t2Tag = new byte[Imsg.length], f4Tag = new byte[32], h1Tag = new byte[32];
            System.out.println("ii2i.get(t) = " + ii2i.get(t));
            pph.use_T2(Imsg, t2Tag);
            pph.use_F4(Imsg, f4Tag);
            h1Tag = pph.use_H1(Imsg);
            String sh1 = new BigInteger(h1Tag).toString(), st2 = new BigInteger(t2Tag).toString(), sf4 = new BigInteger(f4Tag).toString();
            data.add(new tokenNode(st2, sf4, sh1));
        }
        long tokenet=System.currentTimeMillis();
        System.out.println("token产生(tokenet-tokenst) = " + (tokenet - tokenst)+"ms");
    }

    public ArrayList<tokenNode> getData() {
        return data;
    }

    public void data2xml(String address){

    }

}
